﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CalcSharp.Core.ServerPackets
{
    /// <summary>
    /// Server Commands
    /// </summary>
    [Serializable]
    public enum Command
    {
        UploadVar,
        ServerVersionInfo,
        GetVar,
        ListAvailableVars,
        GetUserInfo,
        None
    }

    /// <summary>
    /// Variable Info Pacgage
    /// </summary>
    [Serializable]
    public class VariablePacket
    {
        /// <summary>
        /// Name of variable
        /// </summary>
        public string Name;
        /// <summary>
        /// Owner of variable
        /// </summary>
        public string Owner;
        /// <summary>
        /// Stored snapshots of the variable by DateTime
        /// </summary>
        public DateTime[] Dates;
        /// <summary>
        /// Sizes of the snapshots
        /// </summary>
        public long[] Sizes;
    }

    /// <summary>
    /// User information package
    /// </summary>
    [Serializable]
    public class UserInfoPacket
    {
        /// <summary>
        /// Name of the user
        /// </summary>
        public string UserName;
        /// <summary>
        /// Last Command Runtime
        /// </summary>
        public DateTime LastOperation;
        /// <summary>
        /// Data stored by the user
        /// </summary>
        public long AllDataStored;
    }

    /// <summary>
    /// Error information package
    /// </summary>
    [Serializable]
    public class ErrorPacket
    {
        public int ErrorCode;
        public string Description;

        public ErrorPacket()
        {
            ErrorCode = -1;
            Description = "No Error";
        }

        public ErrorPacket(int code, string text)
        {
            ErrorCode = code;
            Description = text;
        }
    }

    /// <summary>
    /// Command word package
    /// </summary>
    [Serializable]
    public class CommandPacket
    {
        public string Username;
        public string Pass;
        public Command Cmd;
        public Dictionary<string, string> Parameters;

        public CommandPacket()
        {
            Username = "";
            Pass = "";
            Cmd = Command.None;
            Parameters = new Dictionary<string, string>();
        }

        public CommandPacket(string username, string pass, Command cmd)
        {
            this.Cmd = cmd;
        }
    }

    [Serializable]
    public class ServerInfo
    {
        public Version ServerVersion;
        public int NumberOfUsers;
        public long StoredData;
        public int StoredVariables;
        public DateTime ServerTime;
    }
}
